package com.example.viewmodedemo;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.Log;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    ViewModelProvider viewModelProvider ;
    int n=0;

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewModelProvider = ViewModelProviders.of(this);
        final MainViewModel model = ViewModelProviders.of(this).get(MainViewModel.class);
        model.getList().observe(this, new Observer<List<String>>() {
            @Override
            public void onChanged(List<String> strings) {
                for(String str:strings){
                    Log.e("androidLog",str+"===");
                }
            }
        });

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    n++;
                    model.add(n+"");
                    SystemClock.sleep(3000);
                }

            }
        }).start();
    }
}
